package com.horay.springclouddemo.stream.singleton.provider.message.impl;

import com.horay.springclouddemo.stream.singleton.provider.message.MessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import java.util.UUID;

/**
 * 消息提供者实现类
 *
 * @author heyingcheng
 * @date 2020/3/28 19:55
 */
@EnableBinding(Source.class)
public class MessageProviderImpl implements MessageProvider {

    private MessageChannel output;

    public MessageProviderImpl(MessageChannel output) {
        this.output = output;
    }

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        return serial;
    }

}
